package com.gxuwz.leave.service;

import com.gxuwz.leave.dao.UserDao;
import com.gxuwz.leave.entity.User;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class UserServiceImpl implements UserService{

    private UserDao userDao;

    @Override
    public void addUser(User entity) {
        userDao.insert(entity);
    }

    @Override
    public List<User> list(User entity) {
        return userDao.query(entity);
    }

    @Override
    public User findUser(String userid) {
        User user = new User();
        List<User> users = userDao.query(new User(userid));
        if(users.isEmpty()){
            System.out.println("找不到userid=["+userid+"]的记录");
        }else{
            user = users.get(0);
        }
        return user;
    }

    @Override
    public void deleteUser(String userid) {
        userDao.delete(userid);
    }

    @Override
    public void editUser(User entity) {
        userDao.update(entity);
    }

    @Override
    public boolean checkUser(String userid, String password) {
        List<User> userList= userDao.query(new User(userid, password));
        return !userList.isEmpty();
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }
}
